﻿<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        Application["soluottruycap"] = 980;
        Application["online"] = 0;
        Application["ngay_hom_qua"] = 0;
        Application["ngay_hom_nay"] = 0;
    }
    
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started

        ThongKeWebSite thongKeWebSite = new ThongKeWebSite();
        ObjThongKeWebSite objThongKe = new ObjThongKeWebSite();
        //lay thong tin thongke
        objThongKe = thongKeWebSite.getThongKe();
        Application["soluottruycap"] = objThongKe.Tong_so_truy_cap;
        Application["tong_so_hom_nay"] = objThongKe.Tong_so_hom_nay;
        Application["tong_so_hom_qua"] = objThongKe.Tong_so_hom_qua;
        
        Application["soluottruycap"] = int.Parse(Application["soluottruycap"].ToString()) + 1;
        Application["tong_so_hom_nay"] = int.Parse(Application["tong_so_hom_nay"].ToString()) + 1;
        Application["online"] = int.Parse(Application["online"].ToString()) + 1;
        
        //update lai thong ke
        objThongKe = new ObjThongKeWebSite();
        objThongKe.Tong_so_truy_cap = int.Parse(Application["soluottruycap"].ToString());
        objThongKe.Tong_so_hom_nay = int.Parse(Application["tong_so_hom_nay"].ToString());
        objThongKe.Ngay = DateTime.Now.ToString();
        thongKeWebSite.updateThongKe(objThongKe);
    }

    void Session_End(object sender, EventArgs e) 
    {
        Application["online"] = int.Parse(Application["online"].ToString()) - 1;
    }
       
</script>

